<?php
namespace Home\Controller;
use Think\Controller;
class ListController extends Controller {    
     public $Book;
    public function __construct() {
        parent::__construct();
        $this->Book = M('addbook');
    }


    public function liebiao(){
        $this->faxianBook();
        $this->display();
    }

    public function faxianBook() {                        
         $id_arr = $this->Book->field('id')->select();
         shuffle($id_arr); 
         shuffle($id_arr); //打乱数组
         $arr= array_slice($id_arr, 6,8); //截取数组1-3个元素作为数组
         $ids = array();
         foreach ($arr as $k => $v) {   //把二维数组转化为一维数组
             $ids[] = $v['id'];
         }
          $map['id'] = array('in',$ids);
           $faxianBook = $this->Book->field('id,title,suotu')->where($map)->select();
            shuffle($faxianBook);
          

          $faxianBook1= array_slice($faxianBook, 0,4);
          $this->assign('faxianBook1',$faxianBook1);
          $faxianBook2= array_slice($faxianBook, 4,4);
          $this->assign('faxianBook2',$faxianBook2);


    }
    
}